

local amorIconFiles = {
    ['城墙'] = [[UI\Widgets\Console\Human\infocard-neutral-armor-fortified.blp]],
    ['大型'] = [[UI\Widgets\Console\Human\infocard-neutral-armor-large.blp]],
    ['普通'] = [[UI\Widgets\Console\Human\infocard-neutral-armor-small.blp]],
    ['神圣'] = [[UI\Widgets\Console\Human\infocard-armor-hero.blp]],
    ['未知'] = [[UI\Widgets\Console\Human\infocard-neutral-armor-small.blp]],
    ['无装甲']=[[UI\Widgets\Console\Human\infocard-neutral-armor-unarmored.blp]],
    ['小型'] = [[UI\Widgets\Console\Human\infocard-neutral-armor-small.blp]],
    ['英雄'] = [[UI\Widgets\Console\Human\infocard-armor-hero.blp]],
    ['中型'] = [[UI\Widgets\Console\Human\infocard-neutral-armor-medium.blp]],
}

--护甲按钮
class.armor_button = extends(class.button)
{
    reload = true,
    new = function (parent,icon,x,y,w,h)
        local panel = class.armor_button:builder 
        {
            parent = parent,
            x = x,
            y = y,
            w = w,
            h = h,
            normal_image = amorIconFiles['英雄'],
        }
        return panel
    end,

    init = function (self)
        class.button.init(self)
        self.title = self:add_text('护甲：',self.w,3,150,20,10,4)
        self.text = self:add_text('1000',self.w+5,23,150,20,10,4)
        
        self.title:set_color(0xffffff00)
        
        self:set_highlight([[UI\Widgets\BattleNet\bnet-button01-highlight-mouse.blp]])
        return self
    end,

    update = function(self,unit)
        local key1 = ('基础护甲')
        local key2 = ('额外护甲')
        local key3 = ('基础护甲%')
        local base = math.floor(unit:get(key1))
        local ext = math.floor(unit:get(key2))
        local rate = math.floor(unit:get(key3))
        local text = ''
        if unit:has_restriction '无敌' then
            self.text:set_text('|cffff0000无敌的|r')
            return
        end
        base = format_number1(base)
        if ext > 0 then 
            text = ("%s + |cff00ff00%s|r"):format(base, format_number1(ext))
        elseif ext<0 then
            text = ("%s - |cffff0000%s|r"):format(base, format_number1(ext))
        else
            text = base
        end
        self.text:set_text(text)

    end,
    on_button_mouse_enter = function(self)
        local hero = ac.unit.localunit()
        if not hero then
            return
        end
        if hero:has_restriction '无敌' then
            self:tooltip('护甲数据','|cffff0000无敌的|r')
            return 
        end
        local def = hero:get('护甲')
        local tip = ('|cff999999护甲：|r%0.f'):format(def)
        if def>0 then
            tip = ('%s|n|cff999999护甲减伤：|r%0.1f%%'):format(tip,def/(100 + def)*100)
        else
            tip = ('%s|n|cff999999护甲减伤：|r0%%'):format(tip)
        end
        tip = ('%s|n|cff999999移动速度：|r%0.f'):format(tip,hero:get('移动速度'))
        self:tooltip('护甲数据',tip)
    end,
}